#!/bin/sh

#maximum number of tests
MAX=10

echo "=== Test TCP with binary files ==="
CNT=0
for file in /usr/bin/*; do
  if test -r $file; then
    if [ $CNT -lt $MAX ]; then
      rm -f ./tmp
      ./tcp_cp_bin server ./tmp &
      PID=$!
      sleep 0.5
      ./tcp_cp_bin client $file
      sleep 0.5
      kill -9 $PID > /dev/null 2>&1
      cmp ./tmp $file || exit 1
      CNT=`expr $CNT + 1`
      echo "$file : OK"
    fi
  fi
done
echo "=== Test UDP with binary files ==="
CNT=0
for file in /usr/bin/*; do
  if test -r $file; then
    if [ $CNT -lt $MAX ]; then
      rm -f ./tmp
      ./udp_cp_bin server ./tmp &
      PID=$!
      sleep 0.5
      ./udp_cp_bin client $file
      sleep 0.5
      kill -9 $PID > /dev/null 2>&1
      cmp ./tmp $file || exit 1
      CNT=`expr $CNT + 1`
      echo "$file : OK"
    fi
  fi
done
echo "=== Test Local with binary files ==="
CNT=0
for file in /usr/bin/*; do
  if test -r $file; then
    if [ $CNT -lt $MAX ]; then
      rm -f ./tmp
      ./local_cp_bin server ./tmp &
      PID=$!
      sleep 0.5
      ./local_cp_bin client $file
      sleep 0.5
      kill -9 $PID > /dev/null 2>&1
      cmp ./tmp $file || exit 1
      CNT=`expr $CNT + 1`
      echo "$file : OK"
    fi
  fi
done
